<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <button>1</button>
    <button>2</button>
    <button>3</button>

    <script>

        // 伪数组有哪些
        //    arguments                   Arguments
        //    querySelectorAll            NodeList    forEach
        //    byClassName  /  byTagName   HTMLCollection  


        // 转化成真数组


        // for  forEach函数







        var oBtns = document.querySelectorAll('button');

        var oBtns2 = document.getElementsByTagName('button');
        console.log(oBtns2);

        console.log(oBtns);


        var arr = [];
        for (var i = 0; i < oBtns2.length; i++) {
            arr.push(oBtns2[i])
        }


        // for (var i = 0; i < oBtns.length; i++) {
        //     oBtns[i].onclick = function () {
        //         console.log(i);
        //     }
        // }

        arr.forEach(function (v, i) {
            v.onclick = function () {
                console.log(i);
            }
        })

    </script>

</body>

</html>